/**
 * 所有版权归 广西梧州 陈锦韬 所有
 *
 * @Title: TokenConfig
 * @Package com.rx.config
 * @Description: 令牌存储策略
 * @author: 陈锦韬
 * @date: 2020\6\2 0002
 * @version V1.0
 * @Copyright: 2020 陈锦韬  All rights reserved.
 */
package com.rx.zuul.bean;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * @author: Administrator
 * @Description: 令牌存储策略
 * @date: 2020\6\2 0002
 */
@Configuration
public class RxTokenConfig {
    // 签名秘钥
    public String SIGNING_KEY="UAA13";
    /**
     * 令牌存储策略
     */
    @Bean
    public TokenStore tokenStore(){
        // jdbc JdbcTokenStore
        // JwtTokenStore   JSON Web Token
        return new JwtTokenStore(accessTokenConverter());
        // 内存方式生成令牌
        //return new InMemoryTokenStore();
    }

    /**
     * JWT转换
     * @return
     */
    @Bean
    public JwtAccessTokenConverter accessTokenConverter(){
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        converter.setSigningKey(SIGNING_KEY);
        return converter;
    }

    @Bean
    public InternalResourceViewResolver setupViewResolver(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/jsp/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
}
